package com.xinda.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xinda.admin.pojo.ProviderProduct;
import com.xinda.admin.service.IProductService;

@Controller
public class ProductContorller {

	@Autowired
	@Qualifier("productService")
	private IProductService productService;
	
	@RequestMapping(value="productList")
	public String showProductList(int status, String productName, Model model){
		
		List<ProviderProduct> productlist = productService.queryProductes(status, productName);
		
		model.addAttribute("productlist", productlist);
		model.addAttribute("count",productlist.size());
		
		return "admin/product/productList";
	}
	
	@RequestMapping(value="productUpdateOfStatus")
	@ResponseBody
	public void updateStatus(int id, int status){
		productService.updateOneProductStatus(id, status);
	}
	
	@RequestMapping(value="productDetail")
	public String productDetail(int id, Model model) {
		
		ProviderProduct product = productService.queryProductDetail(id);
		
		model.addAttribute("product", product);
		
		return "admin/product/productShow";
	}
	
	@RequestMapping(value="productBatchUp")
	@ResponseBody
	public void productBatchUp(int[] productCheckBox) {
		productService.batchUpdateProductStatus(productCheckBox, 1);
	}
	
	@RequestMapping(value="productBatchDown")
	@ResponseBody
	public void productDown(int[] productCheckBox) {
		productService.batchUpdateProductStatus(productCheckBox, 2);
	}
	
}
